//
//  UIView+LSF.swift
//  hoonpay
//
//  Created by 李胜锋 on 2017/8/22.
//  Copyright © 2017年 lishengfeng. All rights reserved.
//

import Foundation
import UIKit


// MARK: - View 属性便捷访问
extension UIView {
    public var lsf_x:CGFloat {
        get {
            return self.frame.origin.x
        }
        
        set {
            self.frame.origin.x = newValue
        }
    }
    
    public var lsf_y:CGFloat {
        get {
            return self.frame.origin.y
        }
        
        set {
            self.frame.origin.y = newValue
        }
    }
    
    public var lsf_centerX:CGFloat {
        get {
            return self.center.x
        }
        
        set {
            self.center.x = newValue
        }
    }
    
    public var lsf_centerY:CGFloat {
        get {
            return self.center.y
        }
        
        set {
            self.center.y = newValue
        }
    }
    
    public var lsf_width:CGFloat {
        get {
            return self.frame.size.width
        }
        
        set {
            self.frame.size.width = newValue
        }
    }
    
    public var lsf_height:CGFloat {
        get {
            return self.frame.size.height
        }
        
        set {
            self.frame.size.height = newValue
        }
    }
    
    
    public var lsf_right:CGFloat {
        get {
            return self.frame.maxX
        }
        
        set {
            self.lsf_x = newValue - self.lsf_width
        }
    }
    
    public var lsf_bottom:CGFloat {
        get {
            return self.frame.maxY
        }
        
        set {
            self.lsf_y = newValue - self.lsf_height
         }
    }
    
    public var lsf_size:CGSize {
        get {
            return self.frame.size
        }
        
        set {
            self.frame.size = newValue
        }
    }
    
}

// MARK: - UIView链式UI代码
protocol ViewChainable {}
extension ViewChainable where Self:UIView {
    @discardableResult
    func config(_ config: (Self)->Void ) -> Self {
        config(self)
        return self
    }
}

extension UIView:ViewChainable {
    func addHere(toSupereView:UIView) -> Self {
        toSupereView.addSubview(self)
        return self
    }
}
